package controller;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.Ebene;


@WebServlet({ "/Suche", "/Suche.html", "/suche", "/suche.html" })
public class Suche extends SessionControll {
	private static final long serialVersionUID = 1L;

	public Suche() {
		super();
	}
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		if(super.loginPruefen(request, response)) {
			String suche = request.getParameter("suche");
			try {
				Ebene[] ergebnis = ebenenRepository.suche(suche);
				
				request.setAttribute("suchergebnis", ergebnis);
				RequestDispatcher view;
				view = request.getRequestDispatcher("Suche.jsp");
				view.forward(request, response);
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				try {
					new helper.Logging("Fehler Fxxx",e.toString(), null, (byte)1);
				} catch (IOException e2) {
					e2.printStackTrace();
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				try {
					new helper.Logging("Fehler Fxxx",e.toString(), null, (byte)1);
				} catch (IOException e2) {
					e2.printStackTrace();
				}
			}
		}
	}
}
